package com.zzyl.controller;

import cn.hutool.log.Log;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
           @ApiParam(value = "护理项目名称")
           @RequestParam(value = "name",required = false) String name,
           @ApiParam(value = "状态:0-禁用,1-启用")
           @RequestParam(value = "status",required = false) Integer status,
           @ApiParam(value = "当前页码")
           @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
           @ApiParam(value = "每页显示数量")
           @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象",required = true)
            @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理")
    public ResponseResult queryById(
            @ApiParam(value = "护理项目传输id",required = true)
            @PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.queryById(id);
       return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult edit(
            @ApiParam(value = "护理项目传输对象修改信息")
            @RequestBody NursingProjectDto nursingProjectDto){
         nursingProjectService.edit(nursingProjectDto);
         return ResponseResult.success();
    }

    /**
     * 护理项目启动禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动禁用")
    public ResponseResult enableAndDisable(
            @ApiParam(value = "护理项目传输项目id")
            @PathVariable Long id,
            @ApiParam(value = "护理项目传输项目状态")
            Integer status
                ){
        nursingProjectService.enableAndDisable(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteById(
            @ApiParam(value = "要删除护理项目的id")
            @PathVariable Long id
                ){
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}
